<template>
  <div>
    <el-form
      ref="query"
      :model="query"
      :inline="true"
      label-width="80px"
      size="mini"
    >
      <el-form-item label="账号">
        <el-input v-model="query.username" style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item label="图书编号">
        <el-input v-model="query.book_num" style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item label="图书名称">
        <el-input v-model="query.book_name" style="width: 150px"></el-input>
      </el-form-item>
      <el-form-item label="归还时间">
        <el-date-picker
          type="date"
          placeholder="选择日期"
          v-model="query.revert_time"
          style="width: 100%"
        ></el-date-picker>
      </el-form-item>
      <el-button
        @click="bookQuery"
        size="mini"
        type="primary"
        icon="el-icon-search"
        >查询</el-button
      >
      <el-button @click="resetForm" size="mini" icon="el-icon-refresh"
        >重置</el-button
      >
    </el-form>

    <el-table :data="tableData" border size="mini">
      <el-table-column
        type="index"
        :index="indexMethod"
        label="序号"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="username" label="借阅者" width="100">
      </el-table-column>
      <el-table-column prop="book_num" label="图书编号" width="180">
      </el-table-column>
      <el-table-column prop="book_name" label="图书名称" width="140">
      </el-table-column>
      <el-table-column prop="revert_time" label="预计归还时间" width="140">
      </el-table-column>
      <el-table-column prop="content" label="消息内容" width="140">
      </el-table-column>
      <el-table-column prop="created_at" label="时间" width="140">
      </el-table-column>
    </el-table>

    <div style="margin-top: 10px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableDataTotal"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { page } from "../../api/message/message";
export default {
  data() {
    return {
      tableData: [],
      query: { page: 1, limit: 10 },
      tableDataTotal: 0,
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    indexMethod(index) {
      return (this.query.page - 1) * this.query.limit + (index + 1);
    },
    getPage() {
      page(this.query).then((res) => {
        // console.log(res);
        this.tableData = res.data.rows;
        this.tableDataTotal = res.data.count;
      });
    },
    handleSizeChange(val) {
      this.query.limit = val;
      this.getPage();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getPage();
    },
    bookQuery() {
      this.getPage();
    },
    resetForm() {
      this.query = { page: 1, limit: 10 };
      this.getPage();
    },
  },
};
</script>
<style lang="scss" scoped>
</style>